#!/usr/bin/env python

import numpy
import pylab
from math import factorial
from matplotlib.font_manager import FontProperties as FP
import nc_broadcast_probability as ncbp

import broadcast_probability as bcp


fp = FP()
fp.set_size('small')

### SPECIFICATIONS: ###
node_count = 10
packets_needed = 100
packet_range = 500
succesrate_bc = 0.9
succesrate_uc = 0.9
#######################

packets = range(packet_range)


## Calculate values for probability for nc:
y_nc = numpy.zeros(packet_range)
y_bc = numpy.zeros(packet_range)

for packet in packets:
	y_nc[packet] = (ncbp.nc_probability_after_extra_transmissions(packets_needed, packet, succesrate_bc))**node_count

	y_bc[packet] = bcp.bc_probability_after_transmissions(packets_needed, packet, succesrate_bc)**node_count



fig = pylab.figure(figsize=(10,5))
ax = fig.add_subplot(1,1,1)
nc = ax.plot(packets[packets_needed:],y_nc[packets_needed:],'k-')
bc = ax.plot(packets[packets_needed:],y_bc[packets_needed:],'k--')
ax.set_ylim((0,1))
ax.set_yticks(numpy.arange(0,1.1,0.1))
ax.set_frame_on(False)

ax.grid('on')

pylab.legend(["NC Broadcast (Infinite field) - 10% Packet Loss","Naive Broadcast (No Feedback) - 10% Packet Loss"], loc='lower right', prop=fp)

pylab.xlabel('Packet Transmissions')
pylab.ylabel('Probability of '+str(node_count)+' nodes having received \n all '+str(packets_needed)+' needed packets\n\n', ha='center')



pylab.savefig('netcod_plot.eps')

# pylab.show()
